package com.example.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.server.WebSocketServer;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @AUTHOR LYF
 * @DATE 2022/2/11
 * @VERSION 1.0
 * @DESC
 */
@RestController
public class WebSocketController {

    @PostMapping("/push")
    void send(@RequestBody JSONObject req) throws IOException {// @RequestBody String msg,String userId
        //WebSocketServer.getWebSocketMap().get(userId).sendMessage(msg);
        String msg = req.getString("msg");
        String userId = req.getString("userId");
        System.out.println("请求ID:"+userId);
        WebSocketServer.sendInfo(msg,userId);
    }
}
